/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dal;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

/**
 *
 * @author Daniel
 */
public class DALConnection {

    private static Connection connection = null;

    public static Connection getConnectionPostgres(){
        String url, username, password = "";
        url = "jdbc:postgresql://localhost:5432/loja";
        username = "postgres";
        password = "postgres";
        try{
            Class.forName("org.postgresql.Driver");
            connection = DriverManager.getConnection(url, username, password);

        }catch(Exception ex){
            ex.printStackTrace();
        }

        return connection;
    }

    public static Statement getStatement(){
        Statement s = null;
        try{
            s = DALConnection.getConnectionPostgres().createStatement();
        } catch(Exception ex){
            ex.printStackTrace();
        }
        return s;

    }

   public static void closeConnection(){
       try{
           if (connection != null) connection.close();
       } catch(Exception ex){
           ex.printStackTrace();
       }
   }
}
